package cn.gemiman.daoyi.module.cms.controller.app.appsitealbumphoto;

import cn.gemiman.daoyi.framework.common.pojo.CommonResult;
import cn.gemiman.daoyi.framework.common.pojo.PageResult;
import cn.gemiman.daoyi.framework.common.util.object.BeanUtils;
import cn.gemiman.daoyi.module.cms.controller.admin.appsitealbumphoto.vo.AppSiteAlbumPhotoPageReqVO;
import cn.gemiman.daoyi.module.cms.controller.admin.appsitealbumphoto.vo.AppSiteAlbumPhotoRespVO;
import cn.gemiman.daoyi.module.cms.dal.dataobject.appsitealbumphoto.AppSiteAlbumPhotoDO;
import cn.gemiman.daoyi.module.cms.service.appsitealbumphoto.AppSiteAlbumPhotoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import static cn.gemiman.daoyi.framework.common.pojo.CommonResult.success;
import static cn.gemiman.daoyi.framework.web.core.util.WebFrameworkUtils.getAppId;

@Tag(name = "用户 APP - 相册照片")
@RestController
@RequestMapping("/cms/app-site-album-photo")
@Validated
public class AppAppSiteAlbumPhotoController {

    @Resource
    private AppSiteAlbumPhotoService appSiteAlbumPhotoService;

    @GetMapping("/get")
    @Operation(summary = "获得相册照片")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    public CommonResult<AppSiteAlbumPhotoRespVO> getAppSiteAlbumPhoto(@RequestParam("id") Long id) {
        AppSiteAlbumPhotoDO appSiteAlbumPhoto = appSiteAlbumPhotoService.getAppSiteAlbumPhoto(id);
        if (!appSiteAlbumPhoto.getAppId().equals(getAppId())) {
            return success(null);
        }
        return success(BeanUtils.toBean(appSiteAlbumPhoto, AppSiteAlbumPhotoRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得相册照片分页")
    public CommonResult<PageResult<AppSiteAlbumPhotoRespVO>> getAppSiteAlbumPhotoPage(@Valid AppSiteAlbumPhotoPageReqVO pageReqVO) {
        pageReqVO.setAppId(getAppId());
        PageResult<AppSiteAlbumPhotoDO> pageResult = appSiteAlbumPhotoService.getAppSiteAlbumPhotoPage(pageReqVO);
        return success(BeanUtils.toBean(pageResult, AppSiteAlbumPhotoRespVO.class));
    }

}
